<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr = [1, 2, 3, 4, 5];
      function myMap(fn) {
        var res = [];
        //没有将arr作为参数传进来 所以用this指针
        for (var i = 0; i < this.length; i++) {
          res.push(fn(this[i], i, this));
        }
        return res;
      }

      Array.prototype.myMap = myMap;
      console.log(
        arr.myMap(function (item, i, arr) {
          return 2 * item - 1;
        })
      );
    </script>
  </body>
</html>
